#include<bits/stdc++.h>
#define int long long
#define For(i,a,b) for(int i=a;i<=b;++i)
#define Rof(i,a,b) for(int i=a;i>=b;--i)
#define rep(i,a) for(int i=1;i<=a;++i)
#define print(x) printf("%lld\n",(int)x)
#define prn(x) printf("%lld ",(int)x)
using namespace std;
const int N=2e6+5,Mod=1e9+7;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){f=(ch=='-'?-f:f);ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return x*f;
}
int T,n;
char s[N];
int a[N];
int gg[N],pp[N];
int C[102][102],ans;
//~ map<vector<int>,int>mp;
void dfs(int x,int l,int r,int op,int ps){
	if(op){if((l+op-1)/op>r) return;}
	if(x==10){
		For(j,0,9)pp[j]=gg[j];
		For(i,0,n-1){
			if(i!=0)pp[a[i]]--;
			if(pp[a[i]]<0) return;
			//~ cout<<ps<<":";
			For(j,0,a[i+1]-1){
				if(!pp[j]) continue;
				if(i==0&&j==0) continue;
				int p=1;
				int ss=n-i-1;
				pp[j]--;
				For(t,0,9){
					p=p*C[ss][pp[t]];
					if(!(t&7))p%=Mod;
					ss-=(pp[t]);
				}
				pp[j]++;
				ans+=p*ps;
			}
			ans%=Mod;
			//~ puts("");
		}
		pp[a[n]]--;
		if(pp[a[n]]<0)return;
		//~ cout<<ps<<endl;
		ans+=ps;
		
		return;
	}
	if(gg[x]){
		dfs(x+1,l,r,op,ps);
		return ;
	}
	For(i,(op==1?l:0),min(l,r-(x>ps))){
		gg[x]=i;
		dfs(x+1,l-i,r,op-1,ps);
		gg[x]=0;
	}
}
int qzh[N];
/*
int dp[11][105];
inline int solve(){
	ans=0;
	For(i,0,n){
		For(j,0,9) gg[j]=0;
		For(j,1,i)gg[a[j]]++;
		if(i==n){
			int mx=-1,p=0;
			For(j,0,9){
				if(gg[j]>=mx){
					mx=gg[j];
					p=j;
				}
			}
			ans+=p;
			break;
		}
		For(t,0,a[i+1]-1){
			if(i==0&&t==0) continue;
			gg[t]++;
			For(mx,0,9){
				For(ii,gg[mx],n){
					For(j,0,10)For(t,0,n) dp[j][t]=0;
					dp[0][0]=1;
					For(j,0,mx-1){
						For(k,0,n){
							if(dp[j][k]==0) continue;
							For(s,gg[j],ii){
								if(k+s>n) break;
								(dp[j+1][k+s]+=dp[j][k])%=Mod;
							}
						}
					}
					For(k,0,n){
						For(s,ii,ii){
							if(k+s>n) break;
							(dp[mx+1][k+s]+=dp[mx][k])%=Mod;
						}
					}
					For(j,mx+1,9){
						//~ if(dp[j][k])
						For(k,0,n){
							if(dp[j][k]==0) continue;
							//~ if(j==9)cout<<1<<" ";
							For(s,gg[j],ii-1){
								if(k+s>n) break;
								(dp[j+1][k+s]+=dp[j][k])%=Mod;
							}
						}
					}
					//~ For(j,0,9){
						//~ For(k,0,n) cout<<dp[j][k]<<" ";
						//~ puts("");
					//~ }
					//~ cout<<mx<<" ";
					ans+=dp[10][n]*mx;
					ans%=Mod;
					//~ cout<<ans<<endl;
				}
			}
			gg[t]--;
		}
		//~ cout<<ans<<endl;
	}
	return ans;
}*/
signed main(){
	freopen("give.in","r",stdin);
	freopen("give.out","w",stdout);
	C[0][0]=1;
	For(i,1,50){
		C[i][0]=1;
		For(j,1,50){
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%Mod;
		}
	}
	//~ For(i,1,50){
		//~ For(j,1,i){
			//~ cout<<C[i][j]<<" ";
		//~ }puts("");
	//~ }
	For(i,1,14){
		n=i;
		For(j,1,n) a[j]=9;
		ans=0;
		For(mx,1,9){//最大的那一位
		For(i,1,n){
			//~ //int tot=0;
			gg[mx]=i;
			dfs(0,n-i,i,9,mx);
			gg[mx]=0;
		}
		}
		qzh[i]=qzh[i-1]+ans;
		//~ cout<<solve()<<" ";
		//~ qzh[i]=qzh[i-1]+solve();
		qzh[i]%=Mod;
		//~ cout<<qzh[i]<<" ";
	}	
	qzh[15]=qzh[14];
	//~ cout<<fixed<<setprecision(2)<<(1.0*clock()/CLOCKS_PER_SEC)<<"s"<<endl;
	T=read();
	while(T--){ans=0;
		scanf("%s",s+1);
		n=strlen(s+1);
		For(i,1,n) a[i]=s[i]-'0';
		if(n<=16){
			For(mx,1,9){//最大的那一位
			For(i,1,n){
				//~ //int tot=0;
				gg[mx]=i;
				dfs(0,n-i,i,9,mx);
				gg[mx]=0;
			}
			}
			printf("%lld\n",(ans+qzh[n-1])%Mod);
			continue;
		}
		//~ printf("%lld\n",(solve()+qzh[n-1])%Mod);
	}
	return 0;
}
//
